package com.bah.observer;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class Subject<S, A> {
    
    public void attach(Observer<S, A> observer) {
        observers.add(observer);
    }
    public void detach(Observer<S, A> observer) {
    	observers.remove(observer);
    }
    protected void notify(S subject, A arg) {
        for (Observer<S, A> obs : observers) {
            obs.update(subject, arg);
        }
    }
 
    private List<Observer<S, A>> observers = new CopyOnWriteArrayList<Observer<S, A>>(); 
    
}